package com.meepo.basic.schema.feed

import java.io.Serializable

data class Topic(
    val id: String = "",
    val title: String = "",
    val desc: String = "",
    val icon: String = "",
    var stat: Stat? = Stat(),
    val covers: List<Resource>? = arrayListOf()
) : Serializable {

    fun isJoined(): Boolean {
        stat?.let {
            return it.joined
        }

        return false
    }

    fun setJoined(): Topic {
        this.stat?.let {
            it.joined = true
            it.memberCount += 1
        }

        this.stat = Stat(joined = true, memberCount = 1)

        return this
    }

    fun setQuitted(): Topic {
        this.stat?.let {
            it.joined = false
            it.memberCount -= 1
        }

        return this
    }


    data class Stat(
        var joined: Boolean = false,
        var memberCount: Int = 0
    ): Serializable
}